<?php
$profileId=$_SESSION['profileid'];
if(isset($_GET['date3']))
{
	$startDate = $_GET['date3'];
} else {
	$tanggalmulai= date('Y-m-d', strtotime('-1 month'));
	$startDate = $tanggalmulai;
}
if(isset($_GET['date4']))
{
	$endDate = $_GET['date4'];
} else {
$endDate = date('Y-m-d');
}
if(isset($_GET['dimension']))
{
	$dimension = $_GET['dimension'];
} else {
$dimension = "ga:date";
}
?>
<h2 align = "center">Hits</h2>
<div class = "row" align="center">
<a href="index.php?objectives=<?php echo $_GET['objectives']; ?>&start=<?php echo $startDate; ?>&end=<?php echo $endDate; ?>&dimension=ga:date" class="btn btn-default" role="button">Hari</a>
<a href="index.php?objectives=<?php echo $_GET['objectives']; ?>&start=<?php echo $startDate; ?>&end=<?php echo $endDate; ?>&dimension=ga:week" class="btn btn-default" role="button">Minggu</a>
<a href="index.php?objectives=<?php echo $_GET['objectives']; ?>&start=<?php echo $startDate; ?>&end=<?php echo $endDate; ?>&dimension=ga:month" class="btn btn-default" role="button">Bulan</a>
</div>
<div class = "row" >
<?php
$HParams = array(
      'dimensions' => $dimension
		);
$resultsH = $analytics->data_ga->get(
       'ga:' . $profileId,
       $startDate,
       $endDate,
	   'ga:hits',
       $HParams
	   );
	   

 ?>
<script type="text/javascript">
        var chartDataH = [
		<?php
    // Print table rows.
		$x=1;
		foreach ($resultsH->getRows() as $row) {
      
		?>
                {
                    "Date": "<?php echo $row[0]; ?>",
                    "Hits": <?php echo $row[1]; ?>
                }
		<?php
		if($x>=sizeof($resultsH->getRows()))
		{
		?>
		<?php
		}
		else
		{
		?>
		,
		<?php
		}
		$x++;
     
		}
?>
        ];
</script>	
</div>

<script type="text/javascript">
            var chartH;

            AmCharts.ready(function () {
                // SERIAL CHART
                chartH = new AmCharts.AmSerialChart();
                chartH.dataProvider = chartDataH;
                chartH.categoryField = "Date";
                chartH.startDuration = 1;

                // AXES
                // category
                var categoryAxisb = chartH.categoryAxis;
                categoryAxisb.labelRotation = 90;
                categoryAxisb.gridPosition = "start";

                // value
                // in case you don't want to change default settings of value axis,
                // you don't need to create it, as one value axis is created automatically.

                // GRAPH
                var graphb = new AmCharts.AmGraph();
                graphb.valueField = "Hits";
                graphb.balloonText = "[[category]]: <b>[[value]]</b>";
                graphb.type = "column";
                graphb.lineAlpha = 0;
                graphb.fillAlphas = 0.8;
                chartH.addGraph(graphb);

                // CURSOR
                var chartCursorb = new AmCharts.ChartCursor();
                chartCursorb.cursorAlpha = 0;
                chartCursorb.zoomable = false;
                chartCursorb.categoryBalloonEnabled = false;
                chartH.addChartCursor(chartCursorb);

                chartH.creditsPosition = "top-right";

                chartH.write("chartH");
            });
</script>

<div class = "row" >

<div id="chartH" style="width: 100% ; height: 400px;"></div>
</div>




